package com.bluebridgecup.FundamentalsofDataStructures.StackAndQueue;

import java.util.Scanner;

public class SimulateStack {
    static int[] a = new int[100010];
    static int top = 0;

    public static void push(int x) {
        a[++top] = x;
    }
    public static void pop(){
        if(top>0){
            top--;
        }
    }
    public static void empty(){
        if(top==0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
    public static void query(){
        if(top==0){
            System.out.println("empty");
        }else{
            System.out.println(a[top]);
        }
    }
    public static void main(String[] args){
        Scanner in =new Scanner(System.in);
        int n = in.nextInt();
        while(n-->0){
            String op=in.next();
            if(op.equals("push")){
                push(in.nextInt());
            }else if(op.equals("pop")){
                pop();
            }else if(op.equals("empty")){
                empty();
            }else{
                query();
            }

        }
        in.close();
    }

}
